/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.Date;
import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchdienbienhochamException;
import doan.quanlycanbo.portlet.NoSuchdienbienluongException;
import doan.quanlycanbo.portlet.NoSuchquatrinhnghiencuuException;
import doan.quanlycanbo.portlet.model.quatrinhnghiencuu;
import doan.quanlycanbo.portlet.service.base.quatrinhnghiencuuLocalServiceBaseImpl;

/**
 * The implementation of the quatrinhnghiencuu local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link doan.quanlycanbo.portlet.service.quatrinhnghiencuuLocalService} interface.
 * </p>
 *
 * <p>
 * Never reference this interface directly. Always use {@link doan.quanlycanbo.portlet.service.quatrinhnghiencuuLocalServiceUtil} to access the quatrinhnghiencuu local service.
 * </p>
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Nguyen Tuan Vinh
 * @see doan.quanlycanbo.portlet.service.base.quatrinhnghiencuuLocalServiceBaseImpl
 * @see doan.quanlycanbo.portlet.service.quatrinhnghiencuuLocalServiceUtil
 */
public class quatrinhnghiencuuLocalServiceImpl
	extends quatrinhnghiencuuLocalServiceBaseImpl {
	
		public quatrinhnghiencuu getByPrimaryKey(long maqtnn) throws NoSuchquatrinhnghiencuuException, SystemException{
			return quatrinhnghiencuuPersistence.findByPrimaryKey(maqtnn);
		}
		
		public List<quatrinhnghiencuu> getAll() throws SystemException{
			return quatrinhnghiencuuPersistence.findAll();
		}
		
		public List<quatrinhnghiencuu> getByHoso(long mahoso) throws SystemException{
			return quatrinhnghiencuuPersistence.findByHoSo(mahoso);
		}
		
		public quatrinhnghiencuu addQTNC(quatrinhnghiencuu qtnc1, long userId) throws SystemException{
			long maqtnc = CounterLocalServiceUtil.increment(quatrinhnghiencuu.class.getName());
			
			quatrinhnghiencuu qtnc2 = quatrinhnghiencuuPersistence.create(maqtnc);		
			qtnc2.setGroupId(qtnc1.getGroupId());
			qtnc2.setCompanyId(qtnc1.getCompanyId());
			qtnc2.setLanguageId(qtnc1.getLanguageId());
			qtnc2.setMahoso(qtnc1.getMahoso());
			qtnc2.setTungay(qtnc1.getTungay());
			qtnc2.setDenngay(qtnc1.getDenngay());
			qtnc2.setTendetai(qtnc1.getTendetai());
			try {
				resourceLocalService.addResources(qtnc1.getCompanyId(), qtnc1.getGroupId(), userId, 
						quatrinhnghiencuu.class.getName(), qtnc2.getPrimaryKey(), false, true, true);
			} catch (PortalException e) {
				e.printStackTrace();
			}
			
			return quatrinhnghiencuuPersistence.update(qtnc2, false);
		}
		
		public quatrinhnghiencuu updateQTNC(long maqtnc,String tendetai, Date tungay, Date denngay) throws NoSuchdienbienhochamException, SystemException, NoSuchdienbienluongException, NoSuchquatrinhnghiencuuException{
			quatrinhnghiencuu qtnc = quatrinhnghiencuuPersistence.findByPrimaryKey(maqtnc);
			qtnc.setTendetai(tendetai);
			qtnc.setTungay(tungay);
			qtnc.setDenngay(denngay);
			return quatrinhnghiencuuPersistence.update(qtnc, false);
		}
		
		public void deleteQTNC(long maqtnc) throws SystemException, PortalException{
			quatrinhnghiencuu qtnc = quatrinhnghiencuuPersistence.findByPrimaryKey(maqtnc);
			deleteQTNC(qtnc);
		}
		
		public void deleteQTNC(quatrinhnghiencuu qtnc) throws PortalException, SystemException{
			resourceLocalService.deleteResource(qtnc.getCompanyId(), quatrinhnghiencuu.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, qtnc.getPrimaryKey());
			quatrinhnghiencuuPersistence.remove(qtnc);
		}
}



